<template>
  <view class="goods-list">
    <!-- <block v-for="(goods,i) in goodsData" :key="i"> -->
    <view class="goods-item">
      <view class="goods-item-left">
        <radio @click.stop="radioChange(goods)" v-if="showRadio" :checked="goods.goods_state" color="#c00000"></radio>
        <image class="goods-pic" :src="goods.goods_small_logo"></image>
      </view>
      <!-- 右侧 -->
      <view class="goods-item-right">
        <view class="goods-name">{{goods.goods_name}}</view>
        <view class="goods-info-box">
          <view class="goods-price">￥{{Number(goods.goods_price).toFixed(2)}}</view>
          <uni-number-box @change="numberChange" v-if="showNumber" :min="1" :value="goods.goods_count"></uni-number-box>
        </view>
      </view>
    </view>
    <!-- </block> -->
  </view>
</template>

<script>
  import minix from "@/minixs/tabbar-badge.js"
  import {
    mapMutations
  } from 'vuex'
  export default {
    props: {
      goods: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNumber: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        queryObj: {
          query: '',
          cid: '',
          pagenum: 1,
          pagesize: 10
        },
        goodsList: [],
        total: 0
      };
    },
    onLoad(options) {
      // console.log(1213)
      // this.queryObj.query = options.query || ''
      // this.queryObj.cid = options.cid || ''
      // this.getGoodsList()
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount']),
      async getGoodsList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
        if (res.meta.status !== 200) return uni.$showMsg()
        this.goodsList = res.message.goods
      },
      goToDetail(goods) {
        console.log(goods.goods_id)
        uni.navigateTo({
          url: '/subpkg/goods_detail/goods_detail?goods_id=' + goods.goods_id
        })
      },
      radioChange(goods) {
        this.updateGoodsState(goods)
      },
      numberChange(val) {
        console.log(val)
        const obj = {
          goods_id: this.goods.goods_id,
          goods_count: val
        }
        this.updateGoodsCount(obj)
      }
    },

  }
</script>

<style lang="scss">
  .goods-item {
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #efefef;

    .goods-item-left {
      margin-right: 5px;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .goods-pic {
        width: 100px;
        height: 100px;
        display: block;
      }
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;

    .goods-name {
      font-size: 13px;
    }

    .goods-info-box {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .goods-price {
        color: #c00000;
        font-size: 16px;
      }
    }
  }
</style>